'use strict';

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.sequelize.transaction((t) => {
      return Promise.all([
          queryInterface.addColumn('Orders', 'note', {
              type: Sequelize.STRING
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'totalPrice', {
            type: Sequelize.INTEGER,
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'currency', {
            type: Sequelize.INTEGER,
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'status', {
            type: Sequelize.STRING,
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'returned', {
            type: Sequelize.BOOLEAN,
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'UserId', {
            type: Sequelize.INTEGER,
            references: {
              model: 'Users', // name of Target model
              key: 'id', // key in Target model that we're referencing
            },
            onUpdate: 'CASCADE',
            onDelete: 'SET NULL',
          }, { transaction: t }),
          queryInterface.addColumn('Orders', 'CartId', {
            type: Sequelize.INTEGER,
            references: {
              model: 'Carts', // name of Target model
              key: 'id', // key in Target model that we're referencing
            },
            onUpdate: 'CASCADE',
            onDelete: 'SET NULL',
          }, { transaction: t }),
         
          
      ])
    })
  },

  down: (queryInterface, Sequelize) => {
    return queryInterface.sequelize.transaction((t) => {
      return Promise.all([
          queryInterface.removeColumn('Orders', 'note',
           { transaction: t }),
          queryInterface.removeColumn('Orders', 'currency',
           { transaction: t }),
           queryInterface.removeColumn('Orders', 'totalPrice',
           { transaction: t }),
           queryInterface.removeColumn('Orders', 'status',
           { transaction: t }),
           queryInterface.removeColumn('Orders', 'UserId',
           { transaction: t }),
           queryInterface.removeColumn('Orders', 'CartId',
           { transaction: t }),
           queryInterface.removeColumn('Orders', 'returned',
           { transaction: t }),
        
      ])
    })
  
 }
}
